package bs

import scala.xml.NodeSeq
import net.liftweb.http.Templates
import scala.xml.NodeSeq
import net.liftweb._
import http._
import util._
import Helpers._


case class Accordion(pairs: (String, NodeSeq)*) extends LiftComponent{
  override val template = Templates("templates-hidden"::"bs"::"_accordion"::Nil).get
  override def transformer = {
    val accordionId = s"accordion-${(math.random * 100).toInt}"
    ".accordion [id]" #> accordionId &
    ".accordion-group" #> pairs.zipWithIndex.map { case ((title, content), index) =>
      val itemId = s"$accordionId-item-$index"
        ".accordion-toggle [data-parent]" #> s"#$accordionId"
        ".accordion-toggle [href]" #> s"#$itemId" &
        ".accordion-toggle *" #> title &
        ".accordion-body [id]" #> itemId &
          ".accordion-inner" #> content
    }
  }
}
